﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeTop.复习九月份
{
    internal class Sol415
    {
        public string AddStrings(string nums1, string nums2)
        {
            Stack<string> stack = new Stack<string>();
            Console.WriteLine("nums1:   " + nums1 + "   nums2   " + nums2);

            int lenC = nums2.Length;
            int lenR = nums1.Length;
            if (lenC < lenR)
            {

                return AddStrings(nums2, nums1);//c长            
            }
            int next = 0;//进位
            for (int i = 0; i < lenR; i++)
            {
                int curNumC = nums2[lenC - i - 1] - '0';
                int curNumR = nums1[lenR - i - 1] - '0';

                int num = curNumC + curNumR + next;
                next = num / 10;
                int curNum = num % 10;

                Console.WriteLine("curNumC:   " + curNumC + "   curNumR   " + curNumR + "   curNum   " + curNum);

                stack.Push(curNum.ToString());

            }
            for (int i = lenR; i < lenC; i++)
            {
                int curNumC = nums2[lenC - i - 1] - '0';


                int num = curNumC + next;
                next = num / 10;
                int curNum = num % 10;

                stack.Push(curNum.ToString());

            }
            if (next != 0)
            {
                stack.Push(next.ToString());
            }

            string resStr = "";
            while (stack.Count > 0)
            {
                resStr += stack.Pop();
            }
            Console.WriteLine("相加的结果Add：   " + resStr);
            return resStr;




        }
    }

    

}
